Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Component, ReactNode } from 'react' |
||
10 | } |
||
11 | |||
12 | class ErrorBoundary extends Component<IProps, IState> { |
||
|
|||
13 | state = { error: null } |
||
14 | |||
15 | static getDerivedStateFromError(error: Error) { |
||
16 | return { error } |
||
17 | } |
||
18 | |||
19 | componentDidCatch(error: Error, errorInfo: any) { |
||
20 | console.error('From ErrorBoundary:', error, errorInfo) |
||
21 | } |
||
22 | |||
23 | render() { |
||
24 | if (this.state.error) { |
||
25 | return ( |
||
26 | <div className="flex flexCol flexAlCent"> |
||
27 | <Text className="mb32 mt32" tag="h2"> |
||
28 | Something went wrong |
||
29 | </Text> |
||
30 | <Button onClick={() => window.history.go()}> |
||
31 | <Text tag="span">Refresh Page</Text> |
||
32 | </Button> |
||
33 | </div> |
||
34 | ) |
||
35 | } |
||
36 | |||
37 | return this.props.children |
||
38 | } |
||
42 |